Sometimes the process you started hangs and nothing happens in the shell. If you started the process in the foreground (i.e., you executed some command) and it hangs simply use Ctrl-c to kill it. Sometimes it's not that easy though. You may have started an analysis in the background, but for some reason you want to terminate it, now. If you know what the process is that hangs you need to look up it's process ID to kill it.
For example, if my file manager called thunar does not respond and seems to hang I do the following:
ps aux |grep thunar
ps aux gives me a snapshot of all processes running at the moment. The output of this is piped into grep where I filter the output so that I only receive the processes that I am interested in; here, the processes related to the file manager thunar.
I get two lines. The first line is the process I am interested in; it's the file manager. The second line represents my grep pattern matching search. To kill the process I need it's process ID, wich is in the second column of the report I just generated (here, 4316).
SIDETRACK
If you want a cleaner output you can filter the above output once more using an inverse grep search to get rid of the line that reports the grep command you issued:
Sometimes the default kill signal (sigterm) gets intercepted and ignored by the process and the process does not get killed. Should this be the case you can issue a signal that cannot be ignored by the process to be killed (sigkill).
kill-94316
If your shell is unresponsive, but you have an idea which process hung it up, you can open a second shell and log into the system (you can log in to multiple shells on the same machine at the same time!) and kill the offending process from there.
Ideally, you issue kill commands as a non-privileged user. If you're a super user you can kill any(!) process, including those that are integral to the operation of your operating system. An unwise kill command may bring down your computer, instantly. Think before you type!
Sometimes the process you started hangs and nothing happens in the shell. If you started the process in the foreground (i.e., you executed some command) and it hangs simply use Ctrl-c to kill it. Sometimes it's not that easy though. You may have started an analysis in the background, but for some reason you want to terminate it, now. If you know what the process is that hangs you need to look up it's process ID to kill it.
For example, if my file manager called thunar does not respond and seems to hang I do the following:
ps aux gives me a snapshot of all processes running at the moment. The output of this is piped into grep where I filter the output so that I only receive the processes that I am interested in; here, the processes related to the file manager thunar.
The output looks like this:
I get two lines. The first line is the process I am interested in; it's the file manager. The second line represents my grep pattern matching search. To kill the process I need it's process ID, wich is in the second column of the report I just generated (here, 4316).
SIDETRACK
If you want a cleaner output you can filter the above output once more using an inverse grep search to get rid of the line that reports the grep command you issued:
This results in the following report:
Neat, eh?
END OF SIDETRACK
Now the process can be killed:
Sometimes the default kill signal (sigterm) gets intercepted and ignored by the process and the process does not get killed. Should this be the case you can issue a signal that cannot be ignored by the process to be killed (sigkill).
If your shell is unresponsive, but you have an idea which process hung it up, you can open a second shell and log into the system (you can log in to multiple shells on the same machine at the same time!) and kill the offending process from there.
Ideally, you issue kill commands as a non-privileged user. If you're a super user you can kill any(!) process, including those that are integral to the operation of your operating system. An unwise kill command may bring down your computer, instantly. Think before you type!